﻿using Omabar.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Omabar.BLL
{
    public static class RouteFactory
    {
        public static string CreateCharacteristicAndPics(List<CHARACTERISTIC> ccsts, List<PHOTO> photos)
        {
            string innerHTML = string.Empty;
            foreach (var photo in photos)
            {
                innerHTML += "<li data-background=\"" + photo.PHOTO_URL + "\">";
                innerHTML += "<div class=\"CourseTitle\"></div>";
                innerHTML += "<div class=\"tourHighlights\">";
                innerHTML += "<ul>";
                foreach (var ccst in ccsts)
                {
                    innerHTML += "<li>";
                    innerHTML += "<div class=\"h3\">" + ccst.CHARACTERISTIC_NAME + "</div>";
                    innerHTML += "<div class=\"h5\">" + ccst.CHARACTERISTIC_DES + "</div>";
                    innerHTML += "</li>";
                }

                innerHTML += "</ul>";
                innerHTML += "</div>";
                innerHTML += "</li>";
            }

            return innerHTML;
        }

        public static string CreateTrips(List<TRIP> trips)
        {
            var innerHTML = string.Empty;
            foreach (var trip in trips)
            {
                innerHTML += "<div class=\"PackageContent marginLR20 Trip\">";
                innerHTML += "<div class=\"marginB20 fontcolfc3 TripDay\"><span>&#8226;</span>" + trip.TRIP_NAME + "<span>▼</span></div>";
                innerHTML += "<ul>";

                Flight_BLL flightBLL = new Flight_BLL();
                List<FLIGHT> flights = flightBLL.GetModels(string.Format("SELECT FLIGHT_ID,FLIGHT_CODE,FLIGHT_CITY_START,FLIGHT_CITY_END,FLIGHT_TIME_START,FLIGHT_TIME_END,FLIGHT_PRICE FROM FLIGHT WHERE FLIGHT_ID IN (SELECT FLIGHT_ID FROM TRIP_FLIGHT WHERE TRIP_ID='{0}')", trip.TRIP_ID));
                if (flights != null)
                {
                    innerHTML += "<li class=\"icon01\">航班";
                    innerHTML += "<table>";
                    innerHTML += "<thead>";
                    innerHTML += "<tr>";
                    innerHTML += "<th scope=\"col\">出发/到达城市</th>";
                    innerHTML += "<th scope=\"col\">航班号</th>";
                    innerHTML += "<th scope=\"col\">起飞/到达时间</th>";
                    innerHTML += "<th scope=\"col\">飞行时长</th>";
                    innerHTML += "</tr>";
                    innerHTML += "</thead>";
                    innerHTML += "<tbody>";
                    foreach (var flight in flights)
                    {
                        innerHTML += "<tr>";
                        innerHTML += "<td>" + flight.FLIGHT_CITY_START + "/" + flight.FLIGHT_CITY_END + "</td>";
                        innerHTML += "<td>" + flight.FLIGHT_CODE + "</td>";
                        innerHTML += "<td>" + flight.FLIGHT_TIME_START.ToString("HH:mm") + "/" + flight.FLIGHT_TIME_END.ToString("HH:mm") + "</td>";
                        innerHTML += "<td>" + flight.FLIGHT_TIME + "</td>";
                        innerHTML += "</tr>";
                    }

                    innerHTML += "</tbody>";
                    innerHTML += "</table>";
                    innerHTML += "</li>";
                }

                Food_BLL foodBLL = new Food_BLL();
                FOOD food = foodBLL.GetModel(trip.TRIP_FOOD);

                if (food == null)
                {
                    innerHTML += "<li class=\"icon02\">餐饮：<span>早餐:" + " " + "</span><span>午餐:" + " " + "</span><span>晚餐:" + " " + "</span></li>";
                }
                else 
                {
                    innerHTML += "<li class=\"icon02\">餐饮：<span>早餐:" + food.BREAKFAST + "</span><span>午餐:" + food.LUNCH + "</span><span>晚餐:" + food.DINNER + "</span></li>";
                }
                

                Hotel_BLL hotelBLL = new Hotel_BLL();
                HOTEL hotel = hotelBLL.GetModelBySQL(string.Format("SELECT HOTEL_ID,HOTEL_NAME,HOTEL_DES,HOTEL_ADDRESS,HOTEL_WEBSITE,HOTE_DETAIL FROM HOTEL WHERE HOTEL_ID IN (SELECT HOTEL_ID FROM TRIP_HOTEL WHERE TRIP_ID='{0}')", trip.TRIP_ID));

                if (hotel == null)
                {
                    innerHTML += "<li class=\"icon03\">酒店：<span class=\"fontcolfc3\">" + " " + "</span></li>";
                    innerHTML += "<li class=\"icon04\">" + trip.TRIP_DES + "</li>";
                    innerHTML += "</ul>";
                }
                else
                {
                    innerHTML += "<li class=\"icon03\">酒店：<span class=\"fontcolfc3\">" + hotel.HOTEL_NAME + "</span></li>";
                    innerHTML += "<li class=\"icon04\">" + trip.TRIP_DES + "</li>";
                    innerHTML += "</ul>";
                }
                

                Photo_BLL photoBLL = new Photo_BLL();
                List<PHOTO> photos = photoBLL.GetModels(string.Format("SELECT PHOTO_ID,PHOTO_NAME,PHOTO_URL,PHOTO_DES,PHOTO_HOT,PHOTO_COVER FROM PHOTO WHERE PHOTO_ID IN (SELECT PHOTO_ID FROM TRIP_GALLERY WHERE TRIP_ID='{0}')", trip.TRIP_ID));

                innerHTML += "<div class=\"TripPic\">";

                foreach (var photo in photos)
                {
                    innerHTML += "<div>";
                    innerHTML += "<ul>";
                    innerHTML += "<li>";
                    innerHTML += "<img src=\"" + photo.PHOTO_URL + "\" width=\"180\" height=\"120\" alt=\"\" /></li>";
                    innerHTML += "<li class=\"fontColb9\">" + photo.PHOTO_DES + "</li>";
                    innerHTML += "</ul>";
                    innerHTML += "</div>";
                }

                innerHTML += "</div>";
                innerHTML += "</div>";
                innerHTML += "<div class=\"clear borderBottom marginB20\"></div>";
            }

            return innerHTML;
        }

        public static string CreateSpecialItem(List<SPECIALITEM> specialItems)
        {
            var innerHTML = string.Empty;
            foreach (var specialItem in specialItems)
            {
                innerHTML += "<div class=\"marginB40\">";
                innerHTML += "<div class=\"SITitle\"><span class=\"floatL\">" + specialItem.SPECIALITEM_NAME + "</span><span class=\"floatR\">￥" + specialItem.SPECIALITEM_PRICE + " /<span class=\"h4\">人起</span></span></div>";
                innerHTML += "<div class=\"SIContent\">";
                innerHTML += "<div class=\"floatL SIPic\">";
                innerHTML += "<img src=\"" + specialItem.SPECIALITEM_COVER + "\" width=\"320\" height=\"240\" alt=\"\" />";
                innerHTML += "</div>";
                innerHTML += "<div class=\"floatR\">";
                innerHTML += "<div class=\"SIText\">" + specialItem.SPECIALITEM_DES + "</div>";
                innerHTML += "<div class=\"SILink\">";
                innerHTML += "<a href=\"#\">";
                innerHTML += "    <img src=\"images/btn_add.png\" width=\"100\" height=\"30\" alt=\"\" /></a>";
                innerHTML += "</div>";
                innerHTML += "</div>";
                innerHTML += "</div>";
                innerHTML += "</div>";
            }

            return innerHTML;
        }

        public static string CreateHotels(List<HOTEL> hotels)
        {
            var innerHTML = string.Empty;
            foreach (var hotel in hotels)
            {
                Photo_BLL photoBLL = new Photo_BLL();
                List<PHOTO> photos = photoBLL.GetModels(string.Format("SELECT PHOTO_ID,PHOTO_NAME,PHOTO_URL,PHOTO_DES,PHOTO_HOT,PHOTO_COVER FROM PHOTO WHERE PHOTO_ID IN (SELECT PHOTO_ID FROM HOTEL_GALLERY WHERE HOTEL_ID='{0}')", hotel.HOTEL_ID));

                innerHTML += "<div class=\"HotelContent\">";
                innerHTML += "<div class=\"floatL HotelPic\">";
                if (photos.Count == 0)
                {
                    innerHTML += "<img src=\"\" width=\"320\" height=\"240\" alt=\"\" />";
                }
                else
                {
                    innerHTML += "<img src=\"" + photos[0].PHOTO_URL + "\" width=\"320\" height=\"240\" alt=\"\" />";
                }
                innerHTML += "</div>";
                innerHTML += "<div class=\"floatR HotelText\">";
                innerHTML += "<ul>";
                innerHTML += "<li class=\"marginB30\">" + hotel.HOTEL_NAME + "</li>";
                innerHTML += "<li class=\"fontColb9\">" + hotel.HOTEL_DES + "</li>";
                innerHTML += "<li class=\"marginT30\"><a href=\"#\" class=\"fontcolfc3\">查看酒店</a></li>";
                innerHTML += "</ul>";
                innerHTML += "</div>";
                innerHTML += "<div class=\"clear\"></div>";
                innerHTML += "<div class=\"HotelLink fontColb9 lineh24\">";
                innerHTML += "<ul>";
                innerHTML += "<li>酒店管网：<a href=\"#\" class=\"fontcolfc3\">" + hotel.HOTEL_WEBSITE + "</a></li>";
                innerHTML += "<li>酒店地址：" + hotel.HOTEL_ADDRESS + "</li>";
                innerHTML += "<li>酒店描述：" + hotel.HOTE_DETAIL + "</li>";
                innerHTML += "</ul>";
                innerHTML += "</div>";
                innerHTML += "</div>";
                innerHTML += "<div class=\"clear marginB40\"></div>";
            }

            return innerHTML;
        }

        public static string CreateRelatedRoutes(List<ROUTE> routes)
        {
            string innerHTML = string.Empty;
            foreach (var route in routes)
            {
                innerHTML += "<li><a href=\"" + route.ROUTE_ID + ".html\">" + route.ROUTE_NAME + "</a></li>";
            }

            return innerHTML;
        }

        public static string CreateRouteFlightCD(ROUTEFLIGHT rf)
        {
            string innerHTML = "";
            innerHTML += "<div class=\"flightInfo\">";
            innerHTML += "<ul class=\"luggage\">";
            innerHTML += rf.ROUTE_LUGGAGE_CD;
            innerHTML += "</ul>";
            innerHTML += "<ul class=\"TakeOff\">";
            innerHTML += rf.ROUTE_TAKEOFF_CD;
            innerHTML += "</ul>";
            innerHTML += "<ul class=\"Landing\">";
            innerHTML += rf.ROUTE_LANDING_CD;
            innerHTML += "</ul>";
            innerHTML += "</div>";
            return innerHTML;
        }

        public static string CreateRouteFlightBJ(ROUTEFLIGHT rf)
        {
            string innerHTML = "";
            innerHTML += "<div class=\"flightInfo\">";
            innerHTML += "<ul class=\"luggage\">";
            innerHTML += rf.ROUTE_LUGGAGE_BJ;
            innerHTML += "</ul>";
            innerHTML += "<ul class=\"TakeOff\">";
            innerHTML += rf.ROUTE_TAKEOFF_BJ;
            innerHTML += "</ul>";
            innerHTML += "<ul class=\"Landing\">";
            innerHTML += rf.ROUTE_LANDING_BJ;
            innerHTML += "</ul>";
            innerHTML += "</div>";
            return innerHTML;
        }
    }
}